﻿GO

ALTER PROCEDURE [dbo].[bhp_NemoGroupColumnsGet]
	@GroupId				INT
AS
BEGIN
	SELECT 
		t.id as ColumnId,
		t.name as ColumnName,
		ct.EnumType as ColumnType,
		ISNULL(t.rel, 0) as RelatedGroupId,
		ISNULL(c.DisplayName, t.name) as DisplayName,
		ISNULL(c.FormattingValue, '{0}') as FormattingValue,
		ISNULL(c.Sort, 0) as ColumnSort,
		c.RegexValidation,
		c.[Description],
		ISNULL(c.HideForEdition, 0) as HideForEdition,
		c.CustomEditControl,
		t.parent as BelongsToGroupId,
		CASE tp.typ WHEN 'V' THEN 0 ELSE 1 END as Editable
	FROM
		n_Tree t
		INNER JOIN bht_ColumnTypes ct ON t.typ = ct.ColumnType
		LEFT JOIN bht_Columns c ON t.id = c.ColumnId
		INNER JOIN n_Tree tp ON t.parent = tp.id
	WHERE
		(t.parent = @GroupId OR t.parent = (SELECT TOP 1 parent FROM n_Tree WHERE id = @GroupId))
		AND (t.del IS NULL OR t.del = 0)

END